
/*
api: /开头
data: {}
ispost: boolen || string(put, delete)
*/
v.ajax = function (api, data, ispost, func_succ, func_err) {
    var pdata = data || {};
    pdata['__r'] = (new Date()).getTime();

    function func_success(res) {
        func_succ && func_succ(res);
    }

    function func_error(xhr, status, error) {
        if (xhr.status == 401) {
            window.location.href = xhr.responseText;
            return false;
        } else {
            if(ispost) v.showToast({content:"遇到错误啦~",time:3000});
            func_err && func_err('failed');
        }
    }

    var method = ispost ? 'POST' : 'GET';
    if (typeof ispost == 'string') method = ispost;

    var options = {
        url: api,
        data: pdata,
        dataType: 'json',
        method: method,
        type: method,
        timeout: pdata.timeout || 20000,
        success: func_success,
        error: func_error
    };

    if (ispost) {
        options.data = JSON.stringify(pdata);
    }

    options.contentType = 'application/json;charset=UTF-8';

    $.ajax(options);
};
